package com.sgxy.wmservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sgxy.servicebase.exceptionhandler.ERPException;
import com.sgxy.wmservice.entity.WmOrders;
import com.sgxy.wmservice.entity.WmSupplier;
import com.sgxy.wmservice.mapper.WmSupplierMapper;
import com.sgxy.wmservice.service.WmOrdersService;
import com.sgxy.wmservice.service.WmSupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-04-29
 */
@Service
public class WmSupplierServiceImpl extends ServiceImpl<WmSupplierMapper, WmSupplier> implements WmSupplierService {

    // 删除供货商
    // order 关联有供货商的id
    @Autowired
    private WmOrdersService wmOrdersService;
    @Override
    public boolean deleteWmSupplierById(String id) {
        QueryWrapper<WmOrders> wrapper = new QueryWrapper<>();
        wrapper.eq("supplier_id", id);
        int count = wmOrdersService.count(wrapper);
        if(count>0){
            throw new ERPException(20001,"该供货商正被使用，无法删除");
        }
        baseMapper.deleteById(id);
        return true;
    }
}
